package com.newlink.building.userinfo.mvp

import com.newlink.building.common_base.base.BasePresenter
import com.newlink.building.common_base.ext.ss
import com.newlink.building.common_base.model.bean.DeviceListRequest
import com.newlink.building.common_base.model.bean.KitDeviceData
import com.newlink.building.common_base.utils.logDebug
import com.newlink.building.userinfo.mvp.contract.Module_UserInfo_DeviceSettingContract
import com.newlink.building.userinfo.mvp.model.Module_UserInfo_DeviceSettingModel

class Module_UserInfo_DeviceSettingPresenter :
    BasePresenter<Module_UserInfo_DeviceSettingContract.Model, Module_UserInfo_DeviceSettingContract.View>(),
    Module_UserInfo_DeviceSettingContract.Presenter {

    override fun createModel(): Module_UserInfo_DeviceSettingContract.Model? {
        return Module_UserInfo_DeviceSettingModel()
    }


    override fun getDeviceList(request: DeviceListRequest) {
        mModel?.getDeviceList(request)?.ss(mModel, mView) {
            if (it != null) {
                logDebug<Module_UserInfo_DeviceSettingPresenter>("getDeviceList ${it.data}")
                mView?.refreshDeviceList(it.data.total, it.data.list)
                mView?.hideLoading()
            } else {
                logDebug<Module_UserInfo_DeviceSettingPresenter>("getDeviceList data is null")
            }
        }
    }

    override fun editKitDevice(token: String, deviceData: KitDeviceData) {
        mModel?.editKitDevice(token, deviceData)?.ss(mModel, mView) {
            if (it != null) {
                logDebug<Module_UserInfo_DeviceSettingPresenter>("editKitDevice code:${it.code} data:${it.data}")
                mView?.editDeviceResult(it.code == 200)
                mView?.hideLoading()
            } else {
                logDebug<Module_UserInfo_DeviceSettingPresenter>("editKitDevice data is null")
            }
        }
    }

    override fun addKitDevice(token: String, deviceData: KitDeviceData) {
        mModel?.addKitDevice(token, deviceData)?.ss(mModel, mView) {
            if (it != null) {
                logDebug<Module_UserInfo_DeviceSettingPresenter>("addKitDevice code:${it.code} data:${it.data}")
                mView?.addDeviceResult(it.code == 200)
                mView?.hideLoading()
            } else {
                logDebug<Module_UserInfo_DeviceSettingPresenter>("addKitDevice data is null")
            }
        }
    }

    override fun deleteKitDevice(token: String, mac: String) {
        mModel?.deleteKitDevice(token, mac)?.ss(mModel, mView) {
            if (it != null) {
                logDebug<Module_UserInfo_DeviceSettingPresenter>("deleteKitDevice code:${it.code} data:${it.data}")
                mView?.deleteDeviceResult(it.code == 200)
                mView?.hideLoading()
            } else {
                logDebug<Module_UserInfo_DeviceSettingPresenter>("deleteKitDevice data is null")
            }
        }
    }
}